/*
 * $Id$
 */
package com.ptdworld.ratking;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 *
 * @author user
 */
public class IconFileProcess2 {

    /** 用OfflineExplorer下载的PrimeFaces的保存路径 */
    public final static String FONT_ICONS = "D:\\OfflineExplorerPortable\\Download\\www.primefaces.org\\volt\\font-icons.xhtml";

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(FONT_ICONS), "UTF-8"));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FONT_ICONS + "-new2"), "UTF-8"));
        boolean findIcon = false;
        boolean findHiddenFieldSet = false;
        boolean findHiddenDiv = false;
        String line = null;
        while ((line = br.readLine()) != null) {
            if (findIcon) {
                if (line.contains("<span class=\"mls\">")) {
                    findIcon = false;
                    bw.write(line);
                    bw.newLine();
                }
            } else if (findHiddenFieldSet) {
                if (line.contains("</fieldset>")) {
                    findHiddenFieldSet = false;
                }
            } else if (findHiddenDiv) {
                if (line.contains("</div>")) {
                    findHiddenDiv = false;
                }
            } else if (line.contains("<span class=\"icon-")) {
                StringBuilder sb = new StringBuilder(line);
                int index = line.lastIndexOf('>');
                if (index > 0) {
                    findIcon = true;
                    sb.insert(index, '/');
                    bw.write(sb.toString());
                    bw.newLine();
                } else {
                    System.out.println("Error: not found '>'");
                    bw.write(sb.toString());
                    bw.newLine();
                }
            } else if (line.contains("<fieldset class=\"fs0 size1of1 clearfix hidden-true\">")) {
                findHiddenFieldSet = true;
            } else if (line.contains("<div class=\"fs0 bshadow0 clearfix hidden-true\">")) {
                findHiddenDiv = true;
            } else {
                bw.write(line);
                bw.newLine();
            }
        }
    }
}
